/**
 * <copyright>
 * </copyright>
 *

 */
package ms.unicorn.language.languagedef.impl;

import java.util.Collection;

import ms.unicorn.language.languagedef.LanguagedefPackage;
import ms.unicorn.language.languagedef.RelationConstraint;
import ms.unicorn.language.languagedef.RelationViewDef;
import ms.unicorn.language.languagedef.SubViewDef;
import ms.unicorn.language.languagedef.XReferenceExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Relation View Def</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationViewDefImpl#getStyle <em>Style</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationViewDefImpl#getChildren <em>Children</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationViewDefImpl#getConstraints <em>Constraints</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RelationViewDefImpl extends ViewDefImpl implements RelationViewDef
{
  /**
   * The cached value of the '{@link #getStyle() <em>Style</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStyle()
   * @generated
   * @ordered
   */
  protected XReferenceExpression style;

  /**
   * The cached value of the '{@link #getChildren() <em>Children</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getChildren()
   * @generated
   * @ordered
   */
  protected EList<SubViewDef> children;

  /**
   * The cached value of the '{@link #getConstraints() <em>Constraints</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConstraints()
   * @generated
   * @ordered
   */
  protected EList<RelationConstraint> constraints;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected RelationViewDefImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return LanguagedefPackage.Literals.RELATION_VIEW_DEF;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XReferenceExpression getStyle()
  {
    return style;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetStyle(XReferenceExpression newStyle, NotificationChain msgs)
  {
    XReferenceExpression oldStyle = style;
    style = newStyle;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LanguagedefPackage.RELATION_VIEW_DEF__STYLE, oldStyle, newStyle);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setStyle(XReferenceExpression newStyle)
  {
    if (newStyle != style)
    {
      NotificationChain msgs = null;
      if (style != null)
        msgs = ((InternalEObject)style).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.RELATION_VIEW_DEF__STYLE, null, msgs);
      if (newStyle != null)
        msgs = ((InternalEObject)newStyle).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.RELATION_VIEW_DEF__STYLE, null, msgs);
      msgs = basicSetStyle(newStyle, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.RELATION_VIEW_DEF__STYLE, newStyle, newStyle));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<SubViewDef> getChildren()
  {
    if (children == null)
    {
      children = new EObjectContainmentEList<SubViewDef>(SubViewDef.class, this, LanguagedefPackage.RELATION_VIEW_DEF__CHILDREN);
    }
    return children;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<RelationConstraint> getConstraints()
  {
    if (constraints == null)
    {
      constraints = new EObjectContainmentEList<RelationConstraint>(RelationConstraint.class, this, LanguagedefPackage.RELATION_VIEW_DEF__CONSTRAINTS);
    }
    return constraints;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_VIEW_DEF__STYLE:
        return basicSetStyle(null, msgs);
      case LanguagedefPackage.RELATION_VIEW_DEF__CHILDREN:
        return ((InternalEList<?>)getChildren()).basicRemove(otherEnd, msgs);
      case LanguagedefPackage.RELATION_VIEW_DEF__CONSTRAINTS:
        return ((InternalEList<?>)getConstraints()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_VIEW_DEF__STYLE:
        return getStyle();
      case LanguagedefPackage.RELATION_VIEW_DEF__CHILDREN:
        return getChildren();
      case LanguagedefPackage.RELATION_VIEW_DEF__CONSTRAINTS:
        return getConstraints();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_VIEW_DEF__STYLE:
        setStyle((XReferenceExpression)newValue);
        return;
      case LanguagedefPackage.RELATION_VIEW_DEF__CHILDREN:
        getChildren().clear();
        getChildren().addAll((Collection<? extends SubViewDef>)newValue);
        return;
      case LanguagedefPackage.RELATION_VIEW_DEF__CONSTRAINTS:
        getConstraints().clear();
        getConstraints().addAll((Collection<? extends RelationConstraint>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_VIEW_DEF__STYLE:
        setStyle((XReferenceExpression)null);
        return;
      case LanguagedefPackage.RELATION_VIEW_DEF__CHILDREN:
        getChildren().clear();
        return;
      case LanguagedefPackage.RELATION_VIEW_DEF__CONSTRAINTS:
        getConstraints().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_VIEW_DEF__STYLE:
        return style != null;
      case LanguagedefPackage.RELATION_VIEW_DEF__CHILDREN:
        return children != null && !children.isEmpty();
      case LanguagedefPackage.RELATION_VIEW_DEF__CONSTRAINTS:
        return constraints != null && !constraints.isEmpty();
    }
    return super.eIsSet(featureID);
  }

} //RelationViewDefImpl
